<?php

namespace App\Listeners\Subscriber;

use Illuminate\Events\Dispatcher;
use App\Jobs\InspectionReportGenerate;
use App\Events\Inspection\CreatedEvent;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

/**
 * 巡检数据模型事件订阅者
 *
 * Date: 11/05/2018
 * @author George
 * @package App\Listeners\Subscriber
 */
class InspectionEventSubscriber implements ShouldQueue
{
	/**
	 * 当创建巡检记录时分发任务
	 *
	 * Date: 12/05/2018
	 * @author George
	 * @param CreatedEvent $event
	 */
	public function onCreated(CreatedEvent $event)
	{
		InspectionReportGenerate::dispatch($event->inspection);
	}

	/**
	 * 为订阅者注册监听器
	 *
	 * Date: 23/03/2018
	 * @author George
	 * @param Dispatcher $events
	 */
	public function subscribe(Dispatcher $events)
	{
		$events->listen(
			'App\Events\Inspection\CreatedEvent',
			'App\Listeners\Subscriber\InspectionEventSubscriber@onCreated'
		);
	}
}
